package com.example.auth.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.auth.entity.SysUserRoleEntity;
import com.example.auth.service.SysUserRoleService;
import com.example.mallcommon.RestResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 用户角色映射
 *
 * @author yang
 * @date 2021-08-23 23:45:26
 */
@ApiOperation("用户角色映射")
@RestController
@AllArgsConstructor
@RequestMapping("/sysuserrole")
public class SysUserRoleController {

    @Autowired private final  SysUserRoleService sysUserRoleService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param sysUserRole 用户角色映射
     * @return
     */
    @ApiOperation("分页查询")
    @RequestMapping(value="/page",method = RequestMethod.GET)
    public RestResult<IPage<SysUserRoleEntity>> getSysUserRolePage(Page page, SysUserRoleEntity sysUserRole) {
        return  new RestResult<>(sysUserRoleService.page(page,Wrappers.query(sysUserRole)));
    }


    /**
     * id查询用户角色映射
     * @param id id
     * @return RestResult
     */
    @ApiOperation("通过id查询用户角色映射")
    @ApiImplicitParam(name = "uid",value = "用户角色映射编码", required = true,paramType = "path")
    @RequestMapping(value="/{id}",method = RequestMethod.GET)
    public RestResult<SysUserRoleEntity> getById(@PathVariable("id") String id){
        return new RestResult<>(sysUserRoleService.getById(id));
    }

    /**
     * 新增用户角色映射
     * @param sysUserRoleEntity 用户角色映射
     * @return RestResult
     */
    @ApiOperation("新增用户角色映射")
    @ApiImplicitParam(name = "sysUserRole",value = "用户角色映射实体类", required = true,paramType = "body",dataType="SysUserRoleEntity")
    @RequestMapping(method = RequestMethod.POST)
    public RestResult save(@RequestBody SysUserRoleEntity sysUserRoleEntity){
        return new RestResult<>(sysUserRoleService.save(sysUserRoleEntity));
    }

    /**
     * 修改用户角色映射
     * @param sysUserRoleEntity 用户角色映射
     * @return RestResult
     */
    @ApiOperation("修改用户角色映射")
    @RequestMapping(method = RequestMethod.PUT)
    @ApiImplicitParam(name = "sysUserRole",value = "用户角色映射实体类", required = true,paramType = "body",dataType="SysUserRoleEntity")
    public RestResult updateById(@RequestBody SysUserRoleEntity sysUserRoleEntity){
        return new RestResult<>(sysUserRoleService.updateById(sysUserRoleEntity));
    }

    /**
     * 通过id删除用户角色映射
     * @param id id
     * @return RestResult
     */
    @ApiOperation("删除用户角色映射")
    @ApiImplicitParam(name = "uid",value = "用户角色映射编码", required = true,paramType = "path")
    @RequestMapping(value="/{id}",method = RequestMethod.DELETE)
    public RestResult removeById(@PathVariable String id){
        return new RestResult<>(sysUserRoleService.removeById(id));
    }

    /**
     * 查询全部
     * @param
     * @return RestResult
     */
    @ApiOperation("查询全部")
    @RequestMapping(value="/queryAll",method = RequestMethod.GET)
    public RestResult<List<SysUserRoleEntity>> queryAll(){
        return new RestResult<>(sysUserRoleService.list());
    }

}